package org.dydl.dao.system.repository;

import org.dydl.model.system.Area;
import org.dydl.model.system.Loss;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;


@Repository
public interface ILossRepository extends CrudRepository<Area, Integer>, JpaSpecificationExecutor<Area> {

    @Query(value = "FROM Area l ", countQuery = "SELECT count(l.id) FROM Area l ")
    Page<Area> getList(Pageable pageable);

    @Query(value = "FROM Area l WHERE l.name LIKE :name", countQuery = "SELECT count(l.id) FROM Area l WHERE l.name LIKE :name")
    Page<Area> getListLike(@Param("name") String name, Pageable pageable);

    @Query(value = "SELECT * FROM loss WHERE UUID = :uuid", nativeQuery = true)
    Loss findByUuid(@Param("uuid") String uuid);

    @Query(value = "SELECT l.BOM_NO FROM loss l WHERE l.GOODS_UUID = :goodsUuid", nativeQuery = true)
    String findByGoodsUuid(@Param("goodsUuid")String goodsUuid);

    @Query(value = "SELECT * FROM loss WHERE BOM_NO = :bomNo", nativeQuery = true)
    Loss finBomByBomNo(@Param("bomNo") String bomNo);
}
